package com.fps.webshop.member.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fps.webshop.member.entity.MemberEntity;
import com.fps.webshop.member.fegin.OrderService;
import com.fps.webshop.member.service.MemberService;
import com.fps.webshop.common.utils.PageUtils;
import com.fps.webshop.common.utils.R;



/**
 * 会员
 *
 * @author fanpengsen
 * @email fanpengsen@qq.com
 * @date 2021-07-20 14:04:57
 */
@RestController
@RequestMapping("member/member")
public class MemberController {
    @Autowired
    private MemberService umsMemberService;
    
    @Autowired
    private OrderService orderService;
    
    @Value("${member.user.name}")
    private String name;
    
    @Value("${member.user.age}")
    private Integer age;
    
    @GetMapping("/order/{id}")
    public R getOrderById(@PathVariable("id") Long id){
		R order = orderService.info(id);
        return R.ok().put("MenberName", "fps").put("order", order);
    }
    
    /**
     * 信息
     */
    @RequestMapping("/testInfo")
    public R testInfo(){
        return R.ok().put("name", name).put("age", age);
    }
    

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("member:umsmember:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = umsMemberService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("member:umsmember:info")
    public R info(@PathVariable("id") Long id){
		MemberEntity umsMember = umsMemberService.getById(id);

        return R.ok().put("umsMember", umsMember);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("member:umsmember:save")
    public R save(@RequestBody MemberEntity umsMember){
		umsMemberService.save(umsMember);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("member:umsmember:update")
    public R update(@RequestBody MemberEntity umsMember){
		umsMemberService.updateById(umsMember);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("member:umsmember:delete")
    public R delete(@RequestBody Long[] ids){
		umsMemberService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
